package view.LoginRigister;

import Controller.LoginController;
import view.Interface.button.ClickEventHandler;
import view.Interface.window.PublicFatherWindow;
import view.LoginRigister.Conponents.ContainerInputField;
import view.LoginRigister.Conponents.ContainerLoginRigisterButton;

import javax.swing.*;
import java.awt.*;

public class LoginMainWindow extends PublicFatherWindow {


    private final LoginController handler;

    // 构造函数：依赖注入方式传入所有窗口创建逻辑
    public LoginMainWindow(LoginController handler) {
        this.handler = handler;

        setTitle("登录 - 健康管理大师");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel Title = new JPanel(new GridLayout(3,1));
        JLabel BIAOTI = new JLabel("无一烦 - 健康管理大师");
        BIAOTI.setFont(new Font("微软雅黑", Font.BOLD, 24));
        BIAOTI.setHorizontalAlignment(SwingConstants.CENTER); // 内容居中

        Title.add(new JPanel());
        Title.add(BIAOTI);
        Title.add(new JPanel());


        class LoginCenterContainer extends JPanel{
            LoginCenterContainer(JPanel TypeContainer, ContainerLoginRigisterButton ButtonContainer){
                setLayout(new GridLayout(3,1));
                add(Title);
                add(TypeContainer);
                add(ButtonContainer);
            }
        }

        ContainerInputField TypePanels =
                new ContainerInputField();

        ClickEventHandler LoginHandler = ()-> {
            handler.tryLogin(TypePanels.getUsername(), TypePanels.getPassword());

        };
        ClickEventHandler RigisterHandler = handler::gotoRigister;

        ContainerLoginRigisterButton Buttons =
                new ContainerLoginRigisterButton(LoginHandler,RigisterHandler);

        this.add(new LoginCenterContainer(TypePanels,Buttons), BorderLayout.CENTER);
        //this.add(UP, BorderLayout.NORTH);
        //this.add(DOWN, BorderLayout.SOUTH);
        //this.add(LEFT, BorderLayout.WEST);
        //this.add(RIGHT, BorderLayout.EAST);


        Ready(true);
    }





}
